﻿@{
    ViewBag.Title = "Custome";
}

@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>   
}
<form id="form1" runat="server" method="post" style = "width:100%;height:100%">
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">                
          <table style="width:100%;">
            <td style="width:100%;">
                <a class="mini-button" iconCls="icon-ok" onclick="onOk" plain="true">保存</a>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </table>                
    </div>    
    <div id="layout1" class="mini-layout" style="width:900px;height:100%;">
        <div showProxyText="false" region="west" width="300px" showSplitIcon="false" showCollapseButton="false" 
            showCloseButton="false"showSplit ="false" showHeader="false">
            <div 
               <table style="width:200px;">
                    <tr>
                        <td style="width:200px;">基础类</td>          
                    </tr>
                </table> 
            </div>
            <div class="mini-fit" >
                <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                        borderStyle="border:1;" url="../Goods/GetGoodsList"
                        allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                        sortMode="client" showPager="false">
                    <div property="columns">
                        <div field="FName" name="FName" width="200" headeralign="center" allowsort="true">商品条码</div>
                        <div field="FUsedFlag" type="checkboxcolumn" name="FUsedFlag" trueValue="1" falseValue="0" width="60" headeralign="center" allowsort="true">设为常用</div>
                    </div>
                </div>
            </div>              
        </div>
        <div region="east" width="300px" showSplitIcon="false" showCollapseButton="false" 
            showCloseButton="false"showSplit ="false" showHeader="false">
            <div 
               <table style="width:200px;">
                    <tr>
                        <td style="width:200px;">业务类</td>          
                    </tr>
                </table> 
            </div>
            <div class="mini-fit" >
                <div id="datagrid2" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                        borderStyle="border:1;" url="../Goods/GetGoodsList"
                        allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                        sortMode="client" showPager="false">
                    <div property="columns">
                        <div field="FName" name="FName" width="200" headeralign="center" allowsort="true">商品条码</div>
                        <div field="FUsedFlag" type="checkboxcolumn" name="FUsedFlag" trueValue="1" falseValue="0" width="60" headeralign="center" allowsort="true">设为常用</div>
                    </div>
                </div>
            </div>    
        </div>
        <div title="center" showCloseButton="false" region="center">
           <div 
               <table style="width:200px;">
                    <tr>
                        <td style="width:200px;">报表类</td>          
                    </tr>
                </table> 
            </div>
            <div class="mini-fit" >
                <div id="datagrid3" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                        borderStyle="border:1;" url="../Goods/GetGoodsList"
                        allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                        sortMode="client" showPager="false">
                    <div property="columns">
                        <div field="FName" name="FName" width="200" headeralign="center" allowsort="true">商品条码</div>
                        <div field="FUsedFlag" type="checkboxcolumn" name="FUsedFlag" trueValue="1" falseValue="0" width="60" headeralign="center" allowsort="true">设为常用</div>
                    </div>
                </div>
            </div>    
        </div>
    </div>
<script>
    mini.parse();

    var tree = mini.get("treegrid1");
    function FormShown() {
        LoadListData();
        var tabs = mini.get("tabs1");
        var tabStock = tabs.getTab("tabStock");
        if (tabStock) {
            tabs.updateTab(tabStock, { visible: false });
        };
    }

    function collapseAll() {
        tree.collapseAll();
    }

    function expandAll() {
        tree.expandAll();
    }

    function expandLevel(level) {
        tree.expandLevel(level);
        tree.collapseLevel(level + 1);
    }

    //加载用户列表
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
        var mKeys = mini.get("FUserKey").getValue()
        var json = "[{";
        json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'search':'" + mKeys + "'";
        json = json + "}]";
        var grid = mini.get("datagrid1");
        grid.load({ json: json });
    }

    function onSelectionChanged() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.getbyName("FUserID").setValue(row.FItemID);
            var json = '[{"FItemID":' + row.FItemID + ',"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]'
            mini.get("grid1").load({ mjson: json });
            mini.get("grid2").load({ FItemID: row.FItemID });
            var param = "[{'FUserID':'" + row.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]";
            $.post("GetPowerInfo", { json: param }, function (data) {
                var mdata = mini.decode(data);
                if (mdata.data.length > 0) {
                    setData(mdata.data[0]);
                }
                else
                    newData();
            });
            ListData();
        } else {
            mini.alert("请选中一个用户");
        }
    }
    function setUrlData(data) {

    }
    function setData(data) {
        var tabs = mini.get("tabs1");
        var tabPOS = tabs.getTab("tabPOS");
        if (tabPOS) {
            tabs.updateTab(tabPOS, { visible: true });
        };
        mini.get("mChanegelsj").setChecked(data.mChanegelsj);
        mini.get("mClearMoney").setChecked(data.mClearMoney);
        mini.get("mReturnPrs").setChecked(data.mReturnPrs);
        mini.get("mOpenMoneyBox").setChecked(data.mOpenMoneyBox);
        mini.get("mOnePr_Agio").setChecked(data.mOnePr_Agio);
        mini.get("mCancelOrder").setChecked(data.mCancelOrder);
        mini.get("mPrinBjMore").setChecked(data.mPrinBjMore);
        mini.get("mSystemSetup").setChecked(data.mSystemSetup);
        mini.get("mDeleteARow").setChecked(data.mDeleteARow);
        mini.get("mHanguppOrder").setChecked(data.mHanguppOrder);
        mini.get("mPreferential").setChecked(data.mPreferential);
        mini.get("mOrderAgio").setChecked(data.mOrderAgio);
        mini.get("mPr_Largess").setChecked(data.mPr_Largess);
        mini.get("mChangeDjBz").setChecked(data.mChangeDjBz);
        mini.get("mPrinDataBz").setChecked(data.mPrinDataBz);
        mini.get("mUserKey_Bz").setChecked(data.mUserKey_Bz);
        mini.get("mPosOrderBz").setChecked(data.mPosOrderBz);
        mini.get("mField_01").setChecked(data.mField_01);
        mini.get("mField_02").setChecked(data.mField_02);
        mini.get("mField_03").setChecked(data.mField_03);
        mini.get("mField_04").setChecked(data.mField_04);
        mini.get("mField_05").setChecked(data.mField_05);
        mini.get("mField_06").setChecked(data.mField_06);
        mini.get("mField_07").setChecked(data.mField_07);
        mini.get("mField_08").setChecked(data.mField_08);
        mini.get("mPurAmount").setChecked(data.mPurAmount); 
        mini.get("mDepositRet").setChecked(data.mDepositRet);
        mini.get("mFSeeStc").setChecked(data.mFSeeStc);
        mini.getbyName("mMaxPr_Agio").setValue(data.mMaxPr_Agio);
        mini.getbyName("mMaxOrderJe").setValue(data.mMaxOrderJe);
        mini.getbyName("mDepositeTime").setValue(data.mDepositeTime);
    }

    function newData() {
        var tabs = mini.get("tabs1");
        var tabPOS = tabs.getTab("tabPOS");
        if (tabPOS) {
            tabs.updateTab(tabPOS, { visible: false });
        };
        mini.get("mChanegelsj").setChecked(false);
        mini.get("mClearMoney").setChecked(false);
        mini.get("mReturnPrs").setChecked(false);
        mini.get("mOpenMoneyBox").setChecked(false);
        mini.get("mOnePr_Agio").setChecked(false);
        mini.get("mCancelOrder").setChecked(false);
        mini.get("mPrinBjMore").setChecked(false);
        mini.get("mSystemSetup").setChecked(false);
        mini.get("mDeleteARow").setChecked(false);
        mini.get("mHanguppOrder").setChecked(false);
        mini.get("mPreferential").setChecked(false);
        mini.get("mOrderAgio").setChecked(false);
        mini.get("mPr_Largess").setChecked(false);
        mini.get("mChangeDjBz").setChecked(false);
        mini.get("mPrinDataBz").setChecked(false);
        mini.get("mUserKey_Bz").setChecked(false);
        mini.get("mPosOrderBz").setChecked(false);
        mini.get("mField_01").setChecked(false);
        mini.get("mField_02").setChecked(false);
        mini.get("mField_03").setChecked(false);
        mini.get("mField_04").setChecked(false);
        mini.get("mField_05").setChecked(false);
        mini.get("mField_06").setChecked(false);
        mini.get("mField_07").setChecked(false);
        mini.get("mField_08").setChecked(false);
        mini.get("mPurAmount").setChecked(false);
        mini.get("mDepositRet").setChecked(false);
        mini.get("mFSeeStc").setChecked(false);
        mini.getbyName("mMaxPr_Agio").setValue("0");
        mini.getbyName("mMaxOrderJe").setValue("0");
        mini.getbyName("mDepositeTime").setValue("0");

    }

    function saveData() {
        var grid = mini.get("datagrid1");
        var grid2 = mini.get("datagrid2");
        var Menugrid2 = mini.get("grid2");
        var rows = grid.getSelecteds();
        var stocks = grid2.getData();
        var menus = Menugrid2.getData();
        if (rows) {
            var form = new mini.Form("#form1");
            form.validate();
            if (form.isValid() == false) return;
            var data = form.getData(true, false);
            data.users = rows;
            data.stocks = stocks;
            data.menus = menus;
            var datajson = mini.encode(data);            
            var param = parent.window.getSystemAppID();
            $.post("SavePowerInfo", { mjson: datajson, mSystemAppID: param }, function (data) {
                var ret = mini.decode(data);
                if (ret.status == "1")
                    mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                else
                    mini.showTips({ content: ret.error, state: "danger", x: "center", y: "top", timeout: 3000 });
            });
        } else {
            mini.alert("请选中一个用户");
        }
    }


    function ListData() {
        var grid = mini.get("datagrid2");
        var grid2 = mini.get("datagrid1");
        var sSystemAppID = parent.window.getSystemAppID();
        var node = grid2.getSelected()
        if (node) {
            var classid = node.FItemID;
            var json = "[{";
            json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
            json = json + "'mUserID':" + "'" + classid + "',";
            json = json + "'search':" + "'" + mini.getbyName("FSearchKeyS").getValue() + "'";
            json = json + "}]";
            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;
        }
    }

    //搜索资料列表
    function search() {
        ListData();
    }

    function newBill() {
        var grid = mini.get("datagrid2");
        var grid2 = mini.get("datagrid1");
        var uID = parent.window.getSystemAppID();
        var node = grid2.getSelected()
        if (node.FItemID == 0) {
            mini.alert("请选择一个组再新增");
            return;
        }
        mini.open({
            url: "../GetItem/MultIndex",
            title: "分配用户门店权限", width: 700, height: 470,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", sTbName: "UserStock", sSearchKey: '', ClassID: node.FItemID };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if (action) {
                    for (var i = 0; i < action.length; i++) {
                        var newRow = {
                            FItemID: action[i].FItemID, FNumber: action[i].FNumber, FName: action[i].FName
                        };
                        grid.addRow(newRow, grid.getData().length);
                    }
                }
            }
        });
    }

    function removeRows() {
        var grid = mini.get("datagrid2");
        var row = grid.getSelecteds();
        if (row) {
            if (confirm("确定删除选中记录集吗？")) {
                SetRemoveRows();
            }
        } else {
            mini.alert("请选要删除的记录");
        }
    }

    function SetRemoveRows() {
        var grid = mini.get("datagrid2");
        var FSystemAppID = parent.window.getSystemAppID();
        var rows = grid.getSelecteds();
        grid.removeRows(rows);
        var json = "[";
    }
    function onFilter1Changed(e) {
        var typebox = mini.get("typeFilter1");
        var type = typebox.getValue().toLowerCase();

        var namebox = mini.get("nameFilter1");
        var name = namebox.getValue().toLowerCase();

        //多条件组合过滤
        mini.get("grid1").filter(function (row) {

            //name
            var r1 = true;
            if (type) {
                r1 = String(row.FParentName).toLowerCase().indexOf(type) != -1;
            }

            var r2 = true;
            if (name) {
                r2 = String(row.FCaption).toLowerCase().indexOf(name) != -1;
            }
            return r1 && r2;
        });
    }

    function onFilter2Changed(e) {
        var typebox = mini.get("typeFilter2");
        var type = typebox.getValue().toLowerCase();

        var namebox = mini.get("nameFilter2");
        var name = namebox.getValue().toLowerCase();

        //多条件组合过滤
        mini.get("grid2").filter(function (row) {

            //name
            var r1 = true;
            if (type) {
                r1 = String(row.FParentName).toLowerCase().indexOf(type) != -1;
            }

            var r2 = true;
            if (name) {
                r2 = String(row.FCaption).toLowerCase().indexOf(name) != -1;
            }

            return r1 && r2;
        });
    }
    function doAddItems(items) {
        items = mini.clone(items);
        //根据id判断，去除重复的item
        for (var i = items.length - 1; i >= 0; i--) {
            var item = items[i];
            var item2 = mini.get("grid2").findRow(function (row) {
                if (row.FItemID == item.FItemID) return true;
            });
            if (item2) {
                items.removeAt(i);
            }
        }
        mini.get("grid2").addRows(items);
    }

    function adds() {
        var musrgid = mini.getbyName("FUserID").getValue();
        if (String(musrgid) != "") {
            var items = mini.get("grid1").getSelecteds();
            mini.get("grid1").removeRows(items);
            mini.get("grid2").addRows(items);
        }
        else {
            mini.alert("请选择一个用户！");
        }
    }
    function addAll() {
        var musrgid = mini.getbyName("FUserID").getValue();
        if (String(musrgid) != "") {
            var items = mini.get("grid1").getData();
            mini.get("grid1").removeRows(items);
            mini.get("grid2").addRows(items);
        }
        else {
            mini.alert("请选择一个用户！");
        }
    }
    function removes() {
        var items = mini.get("grid2").getSelecteds();
        mini.get("grid2").removeRows(items);
        mini.get("grid1").addRows(items);
    }
    function removeAll() {
        var items = mini.get("grid2").getData();
        mini.get("grid2").removeRows(items);
        mini.get("grid1").addRows(items);
    }
    function upItem() {
        var items = mini.get("grid2").getSelecteds();
        mini.get("grid2").moveUp(items);
    }
    function downItem() {
        var items = mini.get("grid2").getSelecteds();
        mini.get("grid2").moveDown(items);
    }
</script>
</form>